<template>
    <el-row>
        <navbar class="navbarBox" select="2"></navbar>
        <!-- 左边图片 -->
        <div class="flex" style="width: 80%;margin: 90px auto;">
            <div>
                <div class="flex">
                    <div @click="handleClick(leftLive[0].id, type, leftLive[0].media)" class="maxBox" v-if="leftLive[0]">
                        <img :src="leftLive[0].thumbnail" alt srcset style="width: 100%;" />
                        <div :style="{ background: $store.state.personality }" class="hand">进入网络表演间</div>
                    </div>
                    <!-- 中间视频 -->
                    <el-row>
                        <div class="flexFS" style="width: 770px;">
                            <div :key="index" class v-for="(itme, index) in liveList">
                                <div @click="handleClick(itme.id, type, itme.media)" @mouseenter="handleMouseEnter(index)" @mouseleave="handleMouseLeave" class="videoBox hand" v-if="index < 20">
                                    <img :src="itme.thumbnail" style="width: 100%;" />

                                    <!-- 移入的时候显示的信息 -->
                                    <div class="videoHoverBox" v-if="hoverShow == index">
                                        <div>{{ itme.name }}</div>
                                        <div style="margin: 5px 0;">{{ itme.city }}</div>
                                        <div>🔥 {{ itme.heat }}</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- <div style="margin: 30px auto; width: 150px">
          <el-button round style="width: 150px;" @click="more">点击加载更多</el-button>
                        </div>-->
                    </el-row>
                </div>

                <div>
                    <div class="title">🔥更多精彩</div>
                </div>

                <!-- 第二页视频 -->
                <div class="flexFS" style="width: 100%;">
                    <div :key="index" class v-for="(itme, index) in liveList">
                        <div @click="handleClick(itme.id, type, itme.media)" @mouseenter="handleMouseEnter(index)" @mouseleave="handleMouseLeave" class="videoBox hand videoBox2" v-if="index > 19">
                            <img :src="itme.thumbnail" style="width: 100%;" />

                            <!-- 移入的时候显示的信息 -->
                            <div class="videoHoverBox" v-if="hoverShow == index">
                                <div>{{ itme.name }}</div>
                                <div style="margin: 5px 0;">{{ itme.city }}</div>
                                <div>🔥 {{ itme.heat }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- <div style="margin: 30px auto; width: 150px">
          <el-button round style="width: 150px;margin-bottom:50px;margin-left: 170px;" @click="more">点击加载更多</el-button>
                </div>-->
            </div>

            <!-- 右边我关注的 -->
            <div>
                <div style>
                    <el-carousel class="block" height="50px" indicator-position="none" trigger="click">
                        <el-carousel-item :key="item" v-for="item in 4">
                            <img alt src="https://img.alicdn.com/imgextra/i2/O1CN01BwXFn421nnDD1Nx11_!!6000000007030-2-tps-740-140.png" srcset />
                        </el-carousel-item>
                    </el-carousel>
                </div>
                <followWithInterest @custom-event="handleCustomEvent" style="width: 250px;"></followWithInterest>
            </div>
        </div>

        <!-- 播放弹窗 -->
        <div class="playPopup" v-if="playShow">
            <playlive :isLive="true" :worksId.sync="worksId" ref="childRef"></playlive>
        </div>

        <!-- 关闭按钮 -->
        <div @click="closeBtnFun" class="closeBtn hand" v-show="playShow">
            <i class="el-icon-circle-close closeIcon"></i>
        </div>

        <bottom class="bottomBox"></bottom>
    </el-row>
</template>
  
<script>
// @ is an alias to /src
import followWithInterest from '@/components/followWithInterest/followWithInterest.vue'
import playlive from '@/components/playlive/playlive.vue'
import navbar from '@/components/navbar/navbar.vue'
import bottom from '@/components/bottom/bottom.vue'
import list from '@/api/request.json'

export default {
    props: ['type'],
    components: {
        followWithInterest,
        playlive,
        navbar,
        bottom,
    },
    data() {
        return {
            dataList: [],
            currentPlayer: null,
            page: 1,
            loading: true,
            hoverShow: -1,
            playShow: false,
            worksId: '',
            moreList: list.main,
            liveList: [],
            leftLive: [],
        }
    },
    computed: {
        random() {
            let random = Math.floor(Math.random() * 5)
            console.log('随机数', random)
            return random
        },
    },

    created() {
        let liveEnd = localStorage.getItem('liveEnd')
        let liveEndList
        if (liveEnd) {
            liveEndList = liveEnd.split(',')
            console.log('进入')
        } else {
            liveEndList = []
        }

        //字符串转数字
        const floatArray = liveEndList.map((str) => parseInt(str))

        // 使用 filter 方法删除特定 id 的元素
        const filteredArray = list.main.filter((item) => !floatArray.includes(item.id))
        console.log('filteredArray', filteredArray)
        this.liveList = filteredArray
        console.log('this.liveList ', this.liveList)

        let leftLiveEnd = localStorage.getItem('leftLiveEnd')
        let leftLiveEndList
        if (leftLiveEnd) {
            leftLiveEndList = leftLiveEnd.split(',')
        } else {
            leftLiveEndList = []
        }
        const floatArray2 = leftLiveEndList.map((str) => parseInt(str))
        const filteredArray2 = list.leftLive.filter((item) => !floatArray2.includes(item.id))
        this.leftLive = filteredArray2
    },

    mounted() {
        this.getShort()
    },

    methods: {
        handleCustomEvent(data) {
            // 在这里可以处理子组件传递的数据
            console.log('data', data)
            localStorage.setItem('video', data)
            this.playShow = true
            setTimeout(() => {
                this.$refs.childRef.childMethod() // 调用子组件的方法
            }, 500)
        },

        closeBtnFun() {
            this.$nextTick(() => {
                this.$refs.childRef.empty() // 调用子组件的方法
                this.playShow = false
            })
        },
        handleMouseEnter(index) {
            this.hoverShow = index
        },

        handleMouseLeave(index) {
            this.hoverShow = -1
        },
        handleClick(id, type, video) {
            //  打开弹窗
            this.worksId = id
            this.playShow = true
            // 存储数据
            localStorage.setItem('video', video)
            localStorage.setItem('videoId', id)
            setTimeout(() => {
                this.$refs.childRef.childMethod() // 调用子组件的方法
            }, 500)
        },
        getShort() {
            let that = this
            let result = {
                worktype: that.type,
                page: that.page,
                pageSize: 30,
            }
            that.apis.getShort(result).then((res) => {
                if (that.page == 1) {
                    that.dataList = res.data
                    that.loading = false
                } else {
                    //上拉加载
                    that.dataList = [...that.dataList, ...res.data]
                    that.loading = false
                }
            })
        },

        more() {
            console.log()
            this.page++
            this.getShort()
        },
    },
}
</script>
  
<style  lang="scss" scoped>
.imgBox {
    width: 140px;
    height: 140px;
    border-radius: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
}

.flexFS {
    display: flex;
    // justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
}

.box {
    color: var(--themeColor);
}

.videoBox {
    width: 140px;
    height: 140px;
    overflow: hidden;
    margin-left: 10px;
    margin-bottom: 10px;
    border-radius: 10px;
    position: relative;
}

.videoBox2 {
    margin-right: 15px;
    margin-left: 0;
    width: 155px;
    height: 155px;
}

.videoHoverBox {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba($color: #000000, $alpha: 0.5);
    z-index: 99;
    color: #fff;
    padding: 10px;
    font-size: 12px;
}

.flex {
    display: flex;
}

.block {
    width: 290px;
    height: 50px;
    border-radius: 30px;
    margin-bottom: 10px;
}

.title {
    font-size: 24px;
    color: #000;
    font-weight: 700;
    margin-right: 40px;
    margin-bottom: 20px;
    margin-top: 10px;
}

.maxBox {
    border-radius: 10px;
    width: 430px;
    height: 590px;
    // background-color: rgb(36, 126, 96);
    overflow: hidden;
    position: relative;

    div {
        font-size: 14px;
        width: 100px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        position: absolute;
        margin: auto;
        border-radius: 10px;
    }
}

.playPopup {
    width: 100vw;
    height: 100vh;
    background-color: rgba($color: #000000, $alpha: 1);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10000;
    min-width: 1800px;
}

.closeBtn {
    position: fixed;
    top: 140px;
    left: 70px;
    width: 50px;
    height: 50px;
    z-index: 10000;
}

.closeIcon {
    font-size: 50px;
    color: rgb(85, 85, 85);
}

.closeIcon:hover {
    color: #c5c5c5;
}
</style>